 <?php
if ($this->session->userdata('logged_in') == 0) {
    redirect('/login');
}
?>

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" href="<?php echo base_url('assets'); ?>/favicon.ico" type="image/x-icon" />

    <title><?php echo $title; ?></title>

    <link href="<?php echo base_url('assets/css/bootstrap.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/font-awesome/css/font-awesome.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/font-awesome/css/font-awesome.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/plugins/iCheck/custom.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/plugins/chosen/chosen.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/table.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/plugins/jQueryUI/jquery-ui-1.10.4.custom.min.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/plugins/jqGrid/ui.jqgrid.css'); ?>" rel="stylesheet">
    <!-- DatePicker style -->
    <link href="<?php echo base_url('assets/css/plugins/datapicker/datepicker3.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/plugins/daterangepicker/daterangepicker-bs3.css'); ?>" rel="stylesheet">
    <!-- Toastr style -->
    <link href="<?php echo base_url('assets/css/plugins/toastr/toastr.min.css'); ?>" rel="stylesheet">

    <!-- Gritter -->
    <link href="<?php echo base_url('assets/js/plugins/gritter/jquery.gritter.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/animate.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/style.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/mybutton.css'); ?>" rel="stylesheet">
    <!-- Sweet Alert -->
    <link href="<?php echo base_url('assets/css/plugins/sweetalert/sweetalert.css'); ?>" rel="stylesheet">
    <!-- FooTable -->
    <link href="<?php echo base_url('assets/css/plugins/footable/footable.core.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/') ?>/css/plugins/summernote/summernote.css" rel="stylesheet">
    <link href="<?php echo base_url('assets/') ?>/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">
    <link href="<?php echo base_url() ?>assets/css/bootstrap-tagsinput.css" rel="stylesheet">
    <link href="<?php echo base_url() ?>assets/css/bootstrap-multiEmail.css" rel="stylesheet">
    <!-- Data Tables -->
    <link href="<?php echo base_url(); ?>assets/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/css/plugins/dataTables/dataTables.responsive.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/css/plugins/dataTables/dataTables.tableTools.min.css" rel="stylesheet">

    <script src="<?php echo base_url('assets/js/jquery-2.1.1.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/bootstrap.min.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/metisMenu/jquery.metisMenu.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/slimscroll/jquery.slimscroll.min.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/chosen.jquery.js'); ?>"></script>
    <!-- Flot -->
    <script src="<?php echo base_url('assets/js/plugins/flot/jquery.flot.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/flot/jquery.flot.tooltip.min.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/flot/jquery.flot.spline.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/flot/jquery.flot.resize.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/flot/jquery.flot.pie.js'); ?>"></script>

    <!-- Peity -->
    <script src="<?php echo base_url('assets/js/plugins/peity/jquery.peity.min.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/demo/peity-demo.js'); ?>"></script>

    <!-- Custom and plugin javascript -->
    <script src="<?php echo base_url('assets/js/inspinia.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/pace/pace.min.js'); ?>"></script>



    <!-- jQuery UI -->
    <!-- <script src="<?php echo base_url('assets/js/plugins/jquery-ui/jquery-ui.min.js'); ?>"></script> -->

    <!-- GITTER -->
    <script src="<?php echo base_url('assets/js/plugins/gritter/jquery.gritter.min.js'); ?>"></script>

    <!-- Sparkline -->
    <script src="<?php echo base_url('assets/js/plugins/sparkline/jquery.sparkline.min.js'); ?>"></script>

    <!-- Sparkline demo data  -->
    <script src="<?php echo base_url('assets/js/demo/sparkline-demo.js'); ?>"></script>

    <!-- ChartJS-->
    <script src="<?php echo base_url('assets/js/plugins/chartJs/Chart.min.js'); ?>"></script>

    <!-- Date range use moment.js same as full calendar plugin -->
    <script src="<?php echo base_url('assets/js/plugins/fullcalendar/moment.min.js'); ?>"></script>

    <!-- Date range picker -->
    <script src="<?php echo base_url('assets/js/plugins/daterangepicker/daterangepicker.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/datapicker/bootstrap-datepicker.js'); ?>"></script>
    <!-- Toastr -->
    <script src="<?php echo base_url('assets/js/plugins/validate/jquery.validate.min.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/toastr/toastr.min.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/iCheck/icheck.min.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/validate/myvalidator.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/notification.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/notifyme.js'); ?>"></script>
     <!-- FooTable -->
    <script src="<?php echo base_url('assets/js/plugins/footable/footable.all.min.js'); ?>"></script>
    <!-- SUMMERNOTE -->
    <script src="<?php echo base_url('assets/') ?>/js/plugins/summernote/summernote.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/bootstrap-tagsinput.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/bootstrap-multiEmail.js"></script>
    <!-- JS file -->
    <script src="<?php echo base_url('assets/EasyAutocomplete/jquery.easy-autocomplete.js'); ?>"></script>

    <!-- CSS file -->
    <link rel="stylesheet" href="<?php echo base_url('assets/EasyAutocomplete/easy-autocomplete.css'); ?>">

    <!-- Additional CSS Themes file - not required-->
    <link rel="stylesheet" href="<?php echo base_url('assets/EasyAutocomplete/easy-autocomplete.themes.css'); ?>">
    <!-- Sweet alert -->
    <script src="<?php echo base_url('assets/js/plugins/sweetalert/sweetalert.min.js'); ?>"></script>

    <!-- Bootstrap Filestyle -->
    <script src="<?php echo base_url('assets/bootstrap-filestyle/src/bootstrap-filestyle.min.js'); ?>"></script>

    <!-- Data Tables -->
    <script src="<?php echo base_url(); ?>assets/js/plugins/dataTables/jquery.dataTables.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/plugins/dataTables/dataTables.bootstrap.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/plugins/dataTables/dataTables.responsive.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/plugins/dataTables/dataTables.tableTools.min.js"></script>

    <script type="text/javascript" src="<?php echo base_url('assets/3rdparty/my_printing.js'); ?>"></script>
    <script type="text/javascript" src="<?php echo base_url('assets/3rdparty/deployJava.js'); ?>"></script>
    <script type="text/javascript" src="<?php echo base_url('assets/3rdparty/deployJava.js'); ?>"></script>
    <script type="text/javascript" src="<?php echo base_url('assets/qz-websocket.js');?>"></script>
    <script type="text/javascript" src="<?php echo base_url('assets/3rdparty/html2canvas.js');?>"></script>
    <script type="text/javascript" src="<?php echo base_url('assets/3rdparty/jquery.plugin.html2canvas.js');?>"></script>
    <script>
        $(document).ready(function () {
                $('.i-checks').iCheck({
                    checkboxClass: 'icheckbox_square-green',
                    radioClass: 'iradio_square-green',
                });
                $.validator.setDefaults({ ignore: ":hidden:not(select)" });
            });
    </script>
    <script>
    $(document).ready(function() {
        if('<?php echo $this->session->userdata("create") ?>' == 'N'){
            $('.add-tab-btn').remove();
        }
    });
    </script>
</head>
<body>
<div id="wrapper">
        <nav class="navbar-default navbar-static-side" role="navigation" id="navigation">
            <div class="sidebar-collapse">
                <ul class="nav metismenu" id="side-menu">
                    <li class="nav-header">
                        <div class="dropdown profile-element"> <span>
                            <img alt="image" class="img-circle" src="<?php echo base_url('assets/img/logo.png'); ?>" style="width:60px; height:60px;" />
                             </span>
                            <a href="<?php echo base_url('default_controller'); ?>">
                            <span class="clear"> <span class="block m-t-xs"> <strong class="font-bold">Water Utilty System</strong>
                             </span> </span> </a>
                        </div>
                        <div class="logo-element"><a href="<?php echo base_url('default_controller'); ?>">
                            <img alt="image" class="img-circle" src="<?php echo base_url('assets/img/logo.png'); ?>" style="width:60px; height:60px;" /></a>
                        </div>
                    </li>
                    <input type="hidden" id="clickme" value="">
                    <?php
$ss1 = $this->uri->segment(1);
$ss2 = $this->uri->segment(2);
if ($ss1 == FALSE) {
    $this->session->set_userdata(array('moduleid' => 0, 'menuid' => 0, 'formid' => 0));
} else if ($ss2 == FALSE) {
    $this->session->set_userdata(array('menuid' => 0, 'formid' => 0));
}

$am = array();
$amm = array();
$af = array();
$counter = 0;
foreach ($access as $ac) {
    $am[$counter] = $ac->module_id;
    $amm[$counter] = $ac->menu_id;
    $af[$counter] = $ac->form_id;
    $counter++;
}
foreach ($modules as $mods) {
    $active = $mods->module_id == $this->session->userdata('moduleid') ? 'active' : '';
    if (in_array($mods->module_id, $am)) {

        echo "<li class=" . $active . "><a href='#' id='" . $mods->module_id . "'><i class='fa fa-th-large'></i> <span class='nav-label'>" . $mods->module_name . "</span> <span class='fa arrow'></span></a> <ul class='nav nav-second-level'>";

        foreach ($modulemenu as $mmkey) {
            if ($mmkey->module_id == $mods->module_id) {
                if (in_array($mmkey->menu_id, $amm)) {
                    $active2 = $mmkey->menu_id == $this->session->userdata('menuid') ? 'active' : '';
                    echo "<li class='" . $active2 . "'><a href='#'><i class='fa fa-th-list'></i> <span class='nav-label'></span>" . $mmkey->menu_name . "<span class='fa arrow'></span></a>";
                    echo "<ul class='nav nav-third-level'>";

                    foreach ($forms as $former) {
                        if ($former->menu_id == $mmkey->menu_id) {
                            if (in_array($former->form_id, $af)) {
                                $active3 = $former->form_id == $this->session->userdata('formid') ? 'active' : '';
                                echo "<li class='" . $active3 . "'><a href='" . base_url("main/reroute/" . $former->module_id . "/" . $former->menu_id) . "/" . $former->form_id . "'>" . $former->form_name . "</a></li>";
                            }
                        }
                    }

                    echo "</ul></li>";
                }
            }
        }
        echo "</ul></li>";
    }
}

?>
                </ul>
            </div>
        </nav>
        <div id="page-wrapper" class="gray-bg dashbard-1">
        <div class="row border-bottom">
        <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
        <div class="navbar-header">
            <a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="#"><i class="fa fa-bars"></i> </a>
        </div>
        <span id="notify"></span>
        <ul class="nav navbar-top-links navbar-right">

                <li>
                    <span class="m-r-sm text-muted welcome-message">Hi!</span>
                    <strong><?php echo $this->session->userdata('f_name') . ' ' . $this->session->userdata('l_name') ?></strong>
                </li>
                <!-- <li>
                    <a href="<?php echo base_url('/logout'); ?>">
                        <i class="fa fa-sign-out"></i> Log out
                    </a>
                </li> -->
                <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                        <i class="fa fa-sort-down"></i>
                    </a>
                    <ul class="dropdown-menu animated fadeInDown">
                        <li>
                            <a href="#" data-toggle="modal" data-target="#reset">
                                <i class="fa fa-cogs"></i> <small>Change Password</small>
                            </a>
                        </li>
                        <li>
                            <a href="<?php echo base_url('/logout'); ?>">
                                <i class="fa fa-sign-out"></i> <small>Log out</small>
                            </a>
                        </li>
                    </ul>
                </li>
            </ul>
        </nav>
        </div>
        <input type="hidden" id="confirm2" value="0">
        <script>
            $(document).ready(function() {
                $('.clear-btn').click(function(){
                     $('#search table tbody').html('');
                     notifymsg('hide','hide');
                });
            });
        </script>
        <div class="modal inmodal" id="reset">
            <div class="modal-dialog modal-sm">
                <div class="modal-content animated fadeInUp">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <i class="fa fa-lock modal-icon"></i>
                        <h4 class="modal-title">Change Password</h4>
                    </div>
                    <div class="modal-body">
                        <form id="password_form" class="form-horizontal" autocomplete="off">
                            <div class="form-group">
                                <div class="col-sm-12">
                                <input style='text-align: center;' placeholder="New Password" type="password" id="new_pass" name="new_pass" class="form-control"></div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-12">
                                <input style='text-align: center;' placeholder="Re-type Password" type="password" id="repassword" name="re_new_pass" class="form-control"></div>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary" id="save_pass">Save changes</button>
                    </div>
                </div>
            </div>
        </div>
        <script>
            $(document).ready(function() {
                $('#password_form').validate({
                  rules: {
                    new_pass:    {
                          required : true
                    },
                    re_new_pass:    {
                          required : true,
                          equalTo: "#new_pass"
                    }
                  }
                });

                $('#save_pass').click(function(){
                    if($('#password_form').valid() == true){
                        console.log('true');
                        $.ajax({
                            url:'<?php echo base_url(); ?>sample/reset_pass',
                            type: 'POST',
                            data: $('#password_form').serialize(),
                            dataType: 'json',
                            success: function(data){
                                if(data.msg == 'success'){
                                    $('#reset').modal('hide');
                                    notifymsg('success','Password Reset Success !');
                                }else{
                                    notifymsg('danger','Oops! Something\'s not right, Please Contact the Administrator.');
                                }
                                $('#save_pass').removeAttr('disabled=[=');
                            },
                            beforeSend: function(){
                                $('#save_pass').attr('disabled',true);
                            }
                        });
                    }else{console.log('false');}
                });
            });
        </script>